package net.sxnic.item.action;

import java.util.HashSet;
import java.util.Set;

import net.sxinfo.core.dao.Page;
import net.sxinfo.core.dao.hibernate3.HibernateCriteria;
import net.sxinfo.core.dao.hibernate3.HibernateDaoUtils;
import net.sxinfo.core.dao.hibernate3.HibernateOrder;
import net.sxinfo.core.util.WebUtils;
import net.sxnic.comm.utils.PropertyUtil;
import net.sxnic.item.ItemConstants;
import net.sxnic.item.mdata.action.MdataAction;
import net.sxnic.ugr.context.AppContext;
import net.sxnic.ugr.role.Role;
import net.sxnic.ugr.security.AuthorizationManager;
import net.sxnic.ugr.user.User;
import net.sxnic.ugr.user.UserManager;
import net.sxnic.workflow.task.Task;
import net.sxnic.workflow.task.TaskManager;

import org.apache.commons.lang.StringUtils;
import org.hibernate.criterion.Criterion;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * 申报单位或个人 列表
 * 
 * @author yfsun
 * 
 */
@SuppressWarnings("serial")
public class ApproverList extends MdataAction {

	private static String SYMBOL = "-";
	Page datas;
	@Autowired
	UserManager userManager;
	@Autowired
	AuthorizationManager authorizationManager;

	public String execute() throws Exception {
		
		User user = ucenterService.findUserByUserName(AppContext
				.getUserName(request));
		String userPrefix = user.getUserOrder()+SYMBOL;
		int pageNumber = WebUtils.getPageNumber(request);
		int pageSize = WebUtils.getPageSize(request);
	
		DetachedCriteria dc = DetachedCriteria.forClass(User.class);
		dc.createAlias("roles", "r").add(Restrictions.eq("r.role", "approver"));
		dc.add(Restrictions.like("username", userPrefix+"%"));
		dc.addOrder(Order.asc("username"));
		datas = userManager.getPageByDetachedCriteria(pageNumber, pageSize, dc);

		return SUCCESS;
	}

	public Page getDatas() {
		return datas;
	}

	public void setDatas(Page datas) {
		this.datas = datas;
	}

}
